//
//  LXConnectViewController.m
//  bgms_d
//
//  Created by Mountain on 20/2/2019.
//  Copyright © 2019 lachesis-zhu. All rights reserved.
//

#import "LXConnectViewController.h"
#import "LXHomeViewController.h"
#import "BLETransDeviceSingleton.h"
#import "LXConnectPairVC.h"
#import "LXAlertView.h"
#import "LXLineViewController.h"

@interface LXConnectViewController () <BLETransDeviceSingletonDelegate>
{
    BLETransDeviceSingleton *ble;
}

@end

@implementation LXConnectViewController

#pragma mark -  public method

#pragma mark -  life cycle
- (void)dealloc
{
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initializationData];
    [self addNotification];
    
    [self loadUI];
    
    [self loadViewDatas];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    
}

- (void)viewDidAppear:(BOOL)animated
{
    
}

#pragma mark -  over write

#pragma mark -  setter & getter

#pragma mark -  private method
- (void)initializationData
{
    ble = [BLETransDeviceSingleton sharedInstance];
    ble.delegate = self;
}

- (void)loadUI
{
    self.view.backgroundColor = kAppThemeColor;
    self.detailLabel.numberOfLines = 2;
    self.detailLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    self.bleConnectView.hidden = YES;
    
    UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDown:)];
    gesture.numberOfTapsRequired = 1;
    gesture.numberOfTouchesRequired = 1;
    [self.bleConnectView addGestureRecognizer:gesture];
}

- (void)loadViewDatas
{
    
}

- (void)buildNavi
{
    
}

- (void)addNotification
{
    
}

#pragma mark -  notification

#pragma mark -  network


#pragma mark -  event handle
- (IBAction)startDown:(id)sender {
    NSString *name = [self getObjectForKey:BLUENAME];
    if (name && ![name isEqualToString:@""]) {
        LXHomeViewController *homeVC = [[LXHomeViewController alloc] initWithNibName:@"LXHomeViewController" bundle:nil];
        LXThemeColorNavigationController *themeNav = [[LXThemeColorNavigationController alloc] initWithRootViewController:homeVC];
        [homeVC bleOperation];
        self.view.window.rootViewController = themeNav;
    } else {
        [ble operation];
    }
}

- (void)tapDown:(UIGestureRecognizer *)gesture {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Bluetooth"]];
}
#pragma mark -  delegate
#pragma mark BLETransDeviceSingletonDelegate
- (void)BLETransDeviceSingletonBlueTooch:(BOOL)open
{
    if (open) {
        self.bleConnectView.hidden = YES;
    } else {
        self.bleConnectView.hidden = NO;
    }
}

- (void)BLETransDeviceSingletonConnected:(BOOL)connected
{
    if (connected) {
        LXConnectPairVC *vc = [[LXConnectPairVC alloc] initWithNibName:NSStringFromClass([LXConnectPairVC class]) bundle:nil];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)BLETransDeviceSingletonSendReady:(BOOL)ready {
    
}
#pragma mark -  lazy load


#pragma mark -  memoryWarning

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
